﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SheepStorage.API.Application.Command.BuildingManagementCommand;
using SheepStorage.API.Application.Command.SheepManagementCommand;

using SheepStorage.API.Baseclass;
using SheepStorage.Domain.DTO.Output;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Controllers
{
    /// <summary>
    /// 羊场管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SheepManagementController : ControllerBase
    {
        private readonly IMediator _mediator;
        ISheepManagementService service;

        public SheepManagementController(IMediator mediator, ISheepManagementService service)
        {
            _mediator = mediator;
            this.service = service;
        }

        /// <summary>
        /// 羊场添加
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> Create([FromForm]SheepManagementCreateCommand  command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 羊场显示
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>

        [HttpPost]
        public async Task<Results<PageOutput<SheepManagement>>> GetSheepManagement(SheepManagementListCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 羊场删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> Del(SheepManagementDelCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 羊场反填
        /// </summary>
        /// <param name="departmentId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Results<SheepManagement>> GetFtSheepManagement(int sheepManagementId)
        {
            return Results<SheepManagement>.DataResult(service.GetFtSheepManagement(sheepManagementId));
        }

        /// <summary>
        /// 羊场修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> Update(SheepManagementUpdaCommand command)
        {
            return await _mediator.Send(command);
        }
    }
}
